package com.ruoyi.common.websocket.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.util.WebAppRootListener;

import lombok.extern.slf4j.Slf4j;

@Configuration
@ComponentScan
@EnableAutoConfiguration
@Slf4j
public class WebServletContextInitializer implements ServletContextInitializer {
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		log.info("===================Servlet容器参数初始化 ===================");
		String value = "65536";//不宜过大,过大容易造成内存溢出
		servletContext.addListener(WebAppRootListener.class);
		servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", value);
		servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize", value);
		servletContext.setInitParameter("org.apache.tomcat.websocket.executorCoreSize", "8");
		servletContext.setInitParameter("org.apache.tomcat.websocket.executorMaxSize", "512");
	}
}